var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2BundleManager = require("BundleManager");
var $2DataManager = require("DataManager");
var $2ExcelManager = require("ExcelManager");
var $2PlantMgr = require("PlantMgr");
var $2UIManager = require("UIManager");
var $2MyUtils = require("MyUtils");
var $2Card = require("Card");
var $2SceneStage = require("SceneStage");
var $2UserDataManager = require("UserDataManager");
var $2TaSdk = require("TaSdk");
var $2pvzChannel = require("pvzChannel");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_PrepareCards = /* */function (_cc$Component59) {
  babel_inherits(y, _cc$Component59);
  var _super75 = babel_createSuper(y);
  function y() {
    var _this166;
    babel_classCallCheck(this, y);
    _this166 = _super75.apply(this, arguments);
    _this166.video1 = null;
    _this166.video2 = null;
    _this166.video3 = null;
    _this166.video4 = null;
    _this166.cards = null;
    _this166.plantIcon = null;
    _this166.info_icon = null;
    _this166.close_icon = null;
    _this166.info_name = null;
    _this166.info_desc = null;
    _this166.info_damage = null;
    _this166.info_cd = null;
    _this166.info_level = null;
    _this166.info_cost = null;
    _this166.cardList = null;
    _this166.atkIcon = null;
    _this166.levelNum = null;
    _this166.videoBtn = null;
    _this166.selectID = 0;
    _this166.lastID = 0;
    _this166.tryTimes = 0;
    _this166.unLockPlantID = [];
    _this166.maxPlantID = 0;
    return _this166;
  }
  babel_createClass(y, [{
    key: "onLoad",
    value: function onLoad() {
      var _this167 = this;
      this.node.on("guideSelect", function () {
        _this167.selectCard(11, _this167.cards.getChildByName("11"));
      }, this);
      $2DataManager.default.instance.clearTempData();
      $2UserDataManager.default.instance.levelGuide || 2 != $2DataManager.default.instance.level || (this.node.getChildByName("DaiFu").active = false);
      for (var _e79 = 0; _e79 < $2DataManager.default.instance.selectPlantID.length; _e79++) {
        if ($2UserDataManager.default.instance.plantLock.includes($2DataManager.default.instance.selectPlantID[_e79])) {
          var _t51 = cc.instantiate($2BundleManager.default.instance.getBundleRes("Prefab", "card/card_1", cc.Prefab));
          _t51.getComponent($2Card.default).init($2DataManager.default.instance.selectPlantID[_e79]);
          _t51.parent = this.cardList;
          _t51.on(cc.Node.EventType.TOUCH_END, function () {
            $2MyUtils.MyUtils.removeArrElement($2DataManager.default.instance.selectPlantID, _t51.getComponent($2Card.default).id);
            $2DataManager.default.instance.selectPlantID.length <= 0 && (_this167.node.getChildByName("x").getComponent(cc.Button).interactable = false);
            _t51.destroy();
            _this167.refreshCardPanel();
          }, this);
        } else {
          $2MyUtils.MyUtils.removeArrElement($2DataManager.default.instance.selectPlantID, $2DataManager.default.instance.selectPlantID[_e79]);
          _e79--;
        }
      }
      this.initCardPanel();
      this.initSunPanel();
      this.initDaiFuPanel();
      this.refreshCardPanel();
      if ($2DataManager.default.instance.selectPlantID.length <= 0) {
        this.node.getChildByName("x").getComponent(cc.Button).interactable = false;
      } else {
        this.node.getChildByName("x").getComponent(cc.Button).interactable = true;
      }
      if ($2pvzChannel.pvzChannel.instance().channel.indexOf("wx") >= 0 && $2pvzChannel.pvzChannel.instance().getCtrl("p9")) {
        this.video1.active = false;
        this.video2.active = false;
        this.video3.active = false;
        this.video4.active = false;
      }
    }
  }, {
    key: "initDaiFuPanel",
    value: function initDaiFuPanel() {
      var e = [];
      e = e.concat($2DataManager.default.instance.rare4Array, $2DataManager.default.instance.rare5Array);
      this.maxPlantID = $2MyUtils.MyUtils.getArrRandomValue(e);
      var t = this.node.getChildByName("DaiFu").getChildByName("Bg").getChildByName("Reward2").getComponentInChildren(sp.Skeleton);
      var a = $2PlantMgr.default.instance().getPlant(this.maxPlantID);
      if ($2BundleManager.default.instance.getBundleRes("Spine", "plant/" + a.dragonName + "/" + a.dragonName, sp.SkeletonData)) {
        t.skeletonData = $2BundleManager.default.instance.getBundleRes("Spine", "plant/" + a.dragonName + "/" + a.dragonName, sp.SkeletonData);
        a.skinName && t.setSkin(a.skinName);
        t.setAnimation(0, "daiji", true);
      } else {
        $2BundleManager.default.instance.loadBundleRes("Spine", "plant/" + a.dragonName + "/" + a.dragonName, sp.SkeletonData, function () {
          t.skeletonData = $2BundleManager.default.instance.getBundleRes("Spine", "plant/" + a.dragonName + "/" + a.dragonName, sp.SkeletonData);
          a.skinName && t.setSkin(a.skinName);
          t.setAnimation(0, "daiji", true);
        });
      }
      this.node.getChildByName("DaiFu").getChildByName("Bg").getChildByName("Reward2").getChildByName("PlantName").getComponent(cc.Label).string = $2PlantMgr.default.instance().getPlant(this.maxPlantID).name + "(满级)";
    }
  }, {
    key: "onClickCloseDaiFu",
    value: function onClickCloseDaiFu() {
      this.node.getChildByName("DaiFu").active = false;
    }
  }, {
    key: "onClickDaiFuVideo",
    value: function onClickDaiFuVideo(e, t) {
      var _this168 = this;
      $2pvzChannel.pvzChannel.instance().showVideo({
        sucCall() {
          var a = e.currentTarget;
          a.getComponent(cc.Button).interactable = false;
          a.getChildByName("videoWhite").active = false;
          a.getComponentInChildren(cc.Label).string = "已领取";
          a.getChildByName("Label").x = 0;
          switch (t) {
            case "1":
              $2SceneStage.default.instance.bombNums++;
              break;
            case "2":
              $2DataManager.default.instance.maxPlantID = _this168.maxPlantID;
              _this168.cards.getChildByName($2DataManager.default.instance.maxPlantID + "").zIndex = -1;
              $2DataManager.default.instance.beforeLevel = $2UserDataManager.default.instance.getPlantLevel($2DataManager.default.instance.maxPlantID);
              $2UserDataManager.default.instance.setPlantLevel($2DataManager.default.instance.maxPlantID, 10, true);
              $2DataManager.default.instance.tryPlant.push($2DataManager.default.instance.maxPlantID);
              _this168.cards.getChildByName($2DataManager.default.instance.maxPlantID + "").getComponent($2Card.default).init($2DataManager.default.instance.maxPlantID);
              _this168.cards.getChildByName($2DataManager.default.instance.maxPlantID + "").getChildByName("Lock").active = false;
              _this168.selectCard($2DataManager.default.instance.maxPlantID, null, false);
              break;
            case "3":
              _this168.node.getChildByName("SunPanel").getComponentInChildren(cc.Label).string = Number(_this168.node.getChildByName("SunPanel").getComponentInChildren(cc.Label).string) + 2e3 + "";
              $2SceneStage.default.instance.goldNums += 2e3;
          }
        },
        failCall() {},
        endCall() {}
      });
    }
  }, {
    key: "initSunPanel",
    value: function initSunPanel() {
      var e;
      e = 20 != $2DataManager.default.instance.level ? $2DataManager.default.instance.level : 100 * $2DataManager.default.instance.level + $2DataManager.default.instance.bossLevel;
      this.node.getChildByName("SunPanel").getComponentInChildren(cc.Label).string = $2ExcelManager.ExcelMgr.instance.GetExcelObject($2ExcelManager.TableName.levelTable)[e].gold + "";
    }
  }, {
    key: "initCardPanel",
    value: function initCardPanel() {
      var _this169 = this;
      var e = [];
      for (var _t52 = 0; _t52 < $2DataManager.default.instance.newPlant.length; _t52++) {
        e.push($2DataManager.default.instance.newPlant[_t52]);
      }
      for (var _t53 = 0; _t53 < $2DataManager.default.instance.plantArray.length; _t53++) {
        $2DataManager.default.instance.newPlant.includes($2DataManager.default.instance.plantArray[_t53]) || e.push($2DataManager.default.instance.plantArray[_t53]);
      }
      var _loop6 = function _loop6(_t54) {
        var a = cc.instantiate($2BundleManager.default.instance.getBundleRes("Prefab", "card/card_1", cc.Prefab));
        _this169.cards.addChild(a);
        a.getComponent($2Card.default).init(e[_t54]);
        if (!$2UserDataManager.default.instance.plantLock.includes(e[_t54])) {
          _this169.unLockPlantID.push(e[_t54]);
          a.getChildByName("Lock").getChildByName("Try").active = true;
        }
        a.name = e[_t54] + "";
        $2DataManager.default.instance.newPlant.includes(e[_t54]) && (a.getChildByName("New").active = true);
        a.on(cc.Node.EventType.TOUCH_END, function () {
          _this169.selectCard(e[_t54], a);
        }, _this169);
      };
      for (var _t54 = 0; _t54 < e.length; _t54++) {
        _loop6(_t54);
      }
      this.selectCard(1, null, false);
    }
  }, {
    key: "refreshCardPanel",
    value: function refreshCardPanel() {
      for (var _e80 = 0; _e80 < this.cards.childrenCount; _e80++) {
        this.cards.children[_e80].opacity = 255;
      }
      for (var _e81 = 0; _e81 < $2DataManager.default.instance.selectPlantID.length; _e81++) {
        this.cards.getChildByName($2DataManager.default.instance.selectPlantID[_e81] + "").opacity = 144;
      }
    }
  }, {
    key: "onClickStart",
    value: function onClickStart() {
      if ($2DataManager.default.instance.selectPlantID.length > 0) {
        $2UIManager.default.instance.closeUI("PrepareCards");
        $2SceneStage.default.instance.play();
      }
    }
  }, {
    key: "selectCard",
    value: function selectCard(e, t) {
      var _this170 = this;
      var a = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
      this.selectID = e;
      if ($2UserDataManager.default.instance.plantLock.includes(e) || $2DataManager.default.instance.tryPlant.includes(e)) {
        this.videoBtn.active = false;
      } else {
        this.videoBtn.active = true;
        $2TaSdk.default.instance.AdsExposure($2TaSdk.VideoIndex.tryPlant);
      }
      if (!$2DataManager.default.instance.selectPlantID.includes(e) && $2DataManager.default.instance.selectPlantID.length < 6 && a && ($2UserDataManager.default.instance.plantLock.includes(e) || $2DataManager.default.instance.tryPlant.includes(e)) && t) {
        $2DataManager.default.instance.selectPlantID.push(e);
        var _a42 = cc.instantiate(t);
        _a42.getChildByName("HighLight").active = false;
        _a42.parent = this.node;
        this.node.getChildByName("x").getComponent(cc.Button).interactable = true;
        cc.tween(_a42).to(.5, {
          x: -450,
          y: 264 - 70 * ($2DataManager.default.instance.selectPlantID.length - 1)
        }).call(function () {
          _a42.parent = _this170.cardList;
          _a42.x = 0;
          _a42.on(cc.Node.EventType.TOUCH_END, function () {
            $2MyUtils.MyUtils.removeArrElement($2DataManager.default.instance.selectPlantID, e);
            $2DataManager.default.instance.selectPlantID.length <= 0 && (_this170.node.getChildByName("x").getComponent(cc.Button).interactable = false);
            _a42.destroy();
            _this170.refreshCardPanel();
          }, _this170);
          _this170.refreshCardPanel();
        }).start();
      }
      if (this.selectID == this.lastID) {
        return;
      }
      if ($2DataManager.default.instance.newPlant.includes(e)) {
        $2MyUtils.MyUtils.removeArrElement($2DataManager.default.instance.newPlant, e);
        this.cards.getChildByName(e + "").getChildByName("New").active = false;
      }
      0 != this.lastID && (this.cards.getChildByName(this.lastID + "").getChildByName("HighLight").active = false);
      this.atkIcon.spriteFrame = 2 == e || 12 == e ? $2BundleManager.default.instance.getBundleRes("BundleTexture", "ui/card_info_cost", cc.SpriteFrame) : 23 == e ? $2BundleManager.default.instance.getBundleRes("BundleTexture", "ui/card_info_cd", cc.SpriteFrame) : $2BundleManager.default.instance.getBundleRes("BundleTexture", "ui/card_info_atk", cc.SpriteFrame);
      this.levelNum.string = $2UserDataManager.default.instance.getPlantLevel(e);
      var n = $2PlantMgr.default.instance().getPlant(e);
      if ($2BundleManager.default.instance.getBundleRes("Spine", "plant/" + n.dragonName + "/" + n.dragonName, sp.SkeletonData)) {
        this.plantIcon.skeletonData = $2BundleManager.default.instance.getBundleRes("Spine", "plant/" + n.dragonName + "/" + n.dragonName, sp.SkeletonData);
        n.skinName && this.plantIcon.setSkin(n.skinName);
        this.plantIcon.setAnimation(0, "daiji", true);
      } else {
        $2BundleManager.default.instance.loadBundleRes("Spine", "plant/" + n.dragonName + "/" + n.dragonName, sp.SkeletonData, function () {
          _this170.plantIcon.skeletonData = $2BundleManager.default.instance.getBundleRes("Spine", "plant/" + n.dragonName + "/" + n.dragonName, sp.SkeletonData);
          n.skinName && _this170.plantIcon.setSkin(n.skinName);
          _this170.plantIcon.setAnimation(0, "daiji", true);
        });
      }
      this.cards.getChildByName(this.selectID + "").getChildByName("HighLight").active = true;
      this.lastID = this.selectID;
      this.info_icon.getComponent(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "PlantIcon/p_" + e, cc.SpriteFrame);
      this.info_name.string = n.name;
      this.info_desc.string = n.desc;
      this.info_damage.string = "" + Math.floor(n.damage[$2UserDataManager.default.instance.getPlantLevel(e) - 1][1] * n.simpleDamage);
      this.info_cd.string = "" + n.cd[$2UserDataManager.default.instance.getPlantLevel(e) - 1][1];
      this.info_cost.string = "" + n.cost[$2UserDataManager.default.instance.getPlantLevel(e) - 1][1];
    }
  }, {
    key: "onClickVideoBtn",
    value: function onClickVideoBtn() {
      var _this171 = this;
      $2pvzChannel.pvzChannel.instance().showVideo({
        sucCall() {
          _this171.tryTimes++;
          $2DataManager.default.instance.tryPlant.push(_this171.selectID);
          _this171.cards.getChildByName(_this171.selectID + "").getChildByName("Lock").active = false;
          _this171.selectCard(_this171.selectID, _this171.cards.getChildByName(_this171.selectID + ""));
          if (2 == _this171.tryTimes) {
            for (var _e82 = 0; _e82 < _this171.unLockPlantID.length; _e82++) {
              _this171.cards.getChildByName(_this171.unLockPlantID[_e82] + "").getChildByName("Lock").active = false;
              $2DataManager.default.instance.tryPlant.includes(_this171.unLockPlantID[_e82]) || $2DataManager.default.instance.tryPlant.push(_this171.unLockPlantID[_e82]);
            }
          }
        },
        failCall() {},
        endCall() {}
      });
    }
  }, {
    key: "clearAll",
    value: function clearAll() {
      this.cardList.removeAllChildren();
      $2DataManager.default.instance.selectPlantID = [];
      this.node.getChildByName("x").getComponent(cc.Button).interactable = false;
      this.refreshCardPanel();
    }
  }]);
  return y;
}(cc.Component);
cc__decorate([ccp_property(cc.Node)], def_PrepareCards.prototype, "video1", undefined);
cc__decorate([ccp_property(cc.Node)], def_PrepareCards.prototype, "video2", undefined);
cc__decorate([ccp_property(cc.Node)], def_PrepareCards.prototype, "video3", undefined);
cc__decorate([ccp_property(cc.Node)], def_PrepareCards.prototype, "video4", undefined);
cc__decorate([ccp_property(cc.Node)], def_PrepareCards.prototype, "cards", undefined);
cc__decorate([ccp_property(sp.Skeleton)], def_PrepareCards.prototype, "plantIcon", undefined);
cc__decorate([ccp_property(cc.Node)], def_PrepareCards.prototype, "info_icon", undefined);
cc__decorate([ccp_property(cc.Node)], def_PrepareCards.prototype, "close_icon", undefined);
cc__decorate([ccp_property(cc.Label)], def_PrepareCards.prototype, "info_name", undefined);
cc__decorate([ccp_property(cc.Label)], def_PrepareCards.prototype, "info_desc", undefined);
cc__decorate([ccp_property(cc.Label)], def_PrepareCards.prototype, "info_damage", undefined);
cc__decorate([ccp_property(cc.Label)], def_PrepareCards.prototype, "info_cd", undefined);
cc__decorate([ccp_property(cc.Label)], def_PrepareCards.prototype, "info_level", undefined);
cc__decorate([ccp_property(cc.Label)], def_PrepareCards.prototype, "info_cost", undefined);
cc__decorate([ccp_property(cc.Node)], def_PrepareCards.prototype, "cardList", undefined);
cc__decorate([ccp_property(cc.Sprite)], def_PrepareCards.prototype, "atkIcon", undefined);
cc__decorate([ccp_property(cc.Label)], def_PrepareCards.prototype, "levelNum", undefined);
cc__decorate([ccp_property(cc.Node)], def_PrepareCards.prototype, "videoBtn", undefined);
def_PrepareCards = cc__decorate([ccp_ccclass], def_PrepareCards);
exports.default = def_PrepareCards;